// luabindtest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream>
#include "lua_manager.h"

using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
    lua_manager mgr;
    if (!mgr.init())
    {
        cout<<mgr.get_lasterror()<<endl;
        return 1;
    }

    string path = get_exe_path();
    path += "\\script";
    mgr.add_path(path.c_str());

    if (!mgr.load_file("test"))
    {
        cout << mgr.get_lasterror() << endl;
        return 1;
    }

    int i = 1;
    while (i)
    {
        try
        {
            cout << luabind::call_function<const char *>(mgr.get_lua(), "test", "Hello ", "World")<<endl;
        }
        catch(luabind::error& e)
        {
            luabind::object error_msg(luabind::from_stack(e.state(), -1));
            std::cout << error_msg << std::endl;
        } 
        cin >> i;
        if (i == 2)
        {
            if (!mgr.load_file("test"))
            {
                cout << mgr.get_lasterror() << endl;
                return 1;
            }
        }
    }

    return 0;
}

